<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="domain.entities.interfaces.*"%>
<%@ page import="util.*"%>
<%@ page import="domain.dao.interfaces.*"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<%@ taglib prefix="nested" uri="http://struts.apache.org/tags-nested"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
<title>Add contact group</title>
<link rel="stylesheet" type="text/css" href="/mdoc-project/css/bootstrap_Boris.css">
<base href="<%=request.getScheme()%>://<%=request.getServerName()%>:<%=request.getServerPort()%><%=request.getContextPath()%>/">
</head>
<body>

	<%
		boolean connected = session
				.getAttribute(DomainUtils.CURRENT_USER_STRING) != null;

		if (connected == false) {
			request.setAttribute(DomainUtils.ALERT_ERROR_STRING,
					"You must be connected");
		}
	%>

	<%@include file="/pages/common_style/header.jsp"%>
	<%@include file="/pages/common_style/alerts.jsp"%>

	<%
		if (connected) {
	%>
	<html:form action="/AddContactGroup">
		<html:errors />
		<br>
		<div class="form-group">
			<label for="group_name">Group name</label>
			<input type="text" class="form-control" id="group_name" name="group_name" value="<%=DomainUtils
							.getNotNullValue(request, "group_name")%>" placeholder="Enter a group name">
			<label for="included_contacts">Included contacts</label>
			<div class="form-control" id="included_contacts" style="overflow: scroll; height: 150px;">
				<%
					ApplicationContext context = util.SpringUtils
									.getApplicationContext();
							String options = "";

							// 					for (Contact c : DAOFactory.getDaoContact().getAll()) {
							IDAOContact daoContact = (IDAOContact) context
									.getBean("beanDAOContact");
							for (IContact c : daoContact.getAll()) {
								options += "<input type=\"checkbox\" name=\"contacts_of_group\" id=\"chbx_"
										+ c.getId()
										+ "\" value=\""
										+ c.getId()
										+ "\"/>"
										+ "<label for=\"chbx_"
										+ c.getId()
										+ "\">"
										+ DomainUtils.displayContact(c)
										+ "</label><br>";
							}
				%>
				<%=options%>
			</div>



			<br>
			<button type="submit" class="btn btn-default">Submit</button>
			<button type="reset" class="btn btn-default">Reset</button>
		</div>
	</html:form>
	<%
		}
	%>

	<%@include file="/pages/common_style/footer.jsp"%>

</body>
</html>